var config = require('../../db/redisConfig');
var redis = require('redis');
module.exports = {
    redisClient:function()
    {
        return redis.createClient({
            port:config.port,
            host:config.host,
            password:config.password,
            db:config.db
        });
    },

    set:function(key,value)
    {
        this.redisClient().set(key,value,function(err,res){
            if(err)
            {
                console.log(err);
            }
        });
    },

    get:function(key,callback)
    {
        this.redisClient().get(key,function(err,res){
            if(err)
            {
                console.log(err);
            }
            callback(res);
        });
    },

    setAccessToken:function(key,value,callback)
    {
        this.redisClient().set(key,value,function(err,res){
            if(err)
            {
                callback({code:500,msg:err});
            }else
            {
                callback({code:200,data:value});
            }
        });
        this.redisClient().expire(key,6500);
    }
}